package info.jimao.newsdk;

import android.content.Context;

import info.jimao.newsdk.callbacks.JuHeListDataCallback;
import info.jimao.newsdk.callbacks.SingleDataCallback;
import info.jimao.newsdk.models.AlmanacModel;
import info.jimao.newsdk.models.HistoryModel;
import info.jimao.newsdk.models.JokeModel;
import info.jimao.newsdk.models.NewsModel;
import info.jimao.newsdk.models.WeatherModel;

/**
 * Created by 智尧
 * on 2016/7/19.
 */
public class JuHeApi {
    private Context context;
    private ApiManager apiManager;

    public JuHeApi(Context context) {
        this.context = context;
        this.apiManager = ApiManager.getInstance();
    }

    //新闻头条
    public void getNews(String type, SingleDataCallback<NewsModel> callback) {
        apiManager.get(ApiRoutes.NEWS)
                .addParams("type", type)
                .addParams("key", "23dd30c49946dc8c6badb28d9483ba7a")
                .tag(context)
                .build()
                .execute(callback);
    }

    //万年历
    public void getAlmanac(String date, SingleDataCallback<AlmanacModel> callback) {
        apiManager.get(ApiRoutes.ALMANAC)
                .addParams("date", date)
                .addParams("key", "26703a6b6fe11fcb40605288f4b963f2")
                .tag(context)
                .build()
                .execute(callback);
    }

    //天气信息
    public void getWeather(String cityName, SingleDataCallback<WeatherModel> callback) {
        apiManager.get(ApiRoutes.WEATHER)
                .addParams("cityname", cityName)
                .addParams("key", "070f812e3a25d3530c1534a54b78d533")
                .tag(context)
                .build()
                .execute(callback);
    }

    //历史上的今天
    public void getHistory(int month, int day, JuHeListDataCallback<HistoryModel> callback) {
        apiManager.get(ApiRoutes.HISTORY)
                .addParams("month", String.valueOf(month))
                .addParams("day", String.valueOf(day))
                .addParams("v", "1.0")
                .addParams("key", "d670dcb5e7715fd8290c003e64e156df")
                .tag(context)
                .build().
                execute(callback);
    }

    public void getJoke(String type, int pageIndex, int pageSize, SingleDataCallback<JokeModel> callback) {
        apiManager.get(type.equals("文字") ? ApiRoutes.JOKE_TEXT : ApiRoutes.JOKE_IMG)
                .addParams("page", String.valueOf(pageIndex))
                .addParams("pagesize", String.valueOf(pageSize))
                .addParams("key", "609414be2396fba8ab8788934a63b13f")
                .tag(context)
                .build()
                .execute(callback);
    }
}
